FROM golang:alpine AS goBuilder

ENV GO111MODULE=on \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOPROXY=https://goproxy.cn

WORKDIR /builder

COPY . .
RUN go build -o leechbox-gis .

FROM pelicanmapping/osgearth

RUN apt-get update && apt-get -y install s3fs && mkdir /tmp/s3

WORKDIR /app
COPY --from=goBuilder /builder/leechbox-gis /app/leechbox-gis

CMD echo "${AWS_KEY}:${AWS_SECRET_KEY}" > /etc/passwd-s3fs && \
    chmod 600 /etc/passwd-s3fs && \
    /usr/bin/s3fs $S3_BUCKET /tmp/s3 \
    -o url=${S3_URL} \
    -o no_check_certificate \
    -o use_path_request_style \
    -o umask=0 \
    -o allow_other \
    -o nonempty \
    -o retries=5 \
    -o connect_timeout=10 && \
    ./leechbox-gis